﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using System.IO;

namespace OficinaTuristicaFE.Controls
{
    /// <summary>
    /// 
    /// </summary>
    public partial class BusinessCard : SurfaceUserControl
    {
        /// <summary>
        /// Constructor
        /// </summary>
        public BusinessCard()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(BusinessCard_Loaded);
        }

        void BusinessCard_Loaded(object sender, RoutedEventArgs e)
        {
            if (((Shared.Item)Video.DataContext).VideoSource != null)
            {

            }
            else
            {
                InformationButton.Visibility = Visibility.Hidden;
                Video.Visibility = Visibility.Hidden;
                PlayButton.Visibility = Visibility.Hidden;
                PauseButton.Visibility = Visibility.Hidden;
                Descripcion.Visibility = Visibility.Visible;
                Direccion.Visibility = Visibility.Visible;
                Mail.Visibility = Visibility.Visible;
                PaginaWeb.Visibility = Visibility.Visible;
                Telefono.Visibility = Visibility.Visible;
                Foto.Visibility = Visibility.Visible;
            }

        }

        //void VCard_PropertyChanged(object sender, PropertyChangedEventArgs e)
        //{
            
        //}
        /// <summary>
        /// property to assign the latitude of the item
        /// </summary>
        public double? Latitude { get; set; }
        /// <summary>
        /// property to assign the longitude of the item
        /// </summary>
        public double? Longitude { get; set; }
        /// <summary>
        /// property to assign the type of activity of the item
        /// </summary>
        public string serviceType { get; set; }

        /// <summary>
        /// property to visualize the image of the item
        /// </summary>
        public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(BusinessCard));
        
        public ImageSource Image
        {
            get { return (ImageSource)GetValue(ImageProperty); }
            set { SetValue(ImageProperty, value); }
        }

        /// <summary>
        /// property to visualize the address of the item
        /// </summary>
        private string _address;

        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }

        /// <summary>
        /// property to visualize the email of the item
        /// </summary>        
        private string _email;

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        /// <summary>
        /// property to visualize the secondary phone of the item
        /// </summary>        
        private string _secondaryPhone;

        public string SecondaryPhone
        {
            get { return _secondaryPhone; }
            set { _secondaryPhone = value; }
        }

        /// <summary>
        /// property to visualize the primary phone of the item
        /// </summary>        
        private string _primaryPhone;

        public string PrimaryPhone
        {
            get { return _primaryPhone; }
            set { _primaryPhone = value; }
        }

        /// <summary>
        /// property to visualize the web page of the item
        /// </summary>        
        private string _web;

        public string Web
        {
            get { return _web; }
            set { _web = value; }
        }

        /// <summary>
        /// property to visualize the description of the item
        /// </summary>        
        private string _description;

        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        /// <summary>
        /// property to access to the video source of the item
        /// </summary>        
        private Uri _videoSource;

        public Uri VideoSource
        {
            get { return _videoSource; }
            set { _videoSource = value;}
        }

        /// <summary>
        /// property to visualize the company name of the item
        /// </summary>        
        private string companyName;

        public string CompanyName
        {
            get { return companyName; }
            set { companyName = value; }
        }

        private string _styleSuffix;

        /// <summary>
        /// Gets or sets the suffix for getting the style for the container.
        /// i.e.: "Routes" would create a "LabelStyleRoutes", "StackPanelStyleRoutes"... etc...
        /// </summary>
        public string StyleSuffix
        {
            get { return _styleSuffix; }
            set
            {
                _styleSuffix = value;
                //  ServiceName.Style = (Style)FindResource("LabelStyle" + value);
                BusinessCardContainer.Style = (Style)FindResource("BussinessCardStyle_" + value);
            }
        }

        /// <summary>
        /// method that is called when the object is initialized
        /// </summary>                
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
        }
                
        

        /// <summary>
        /// Method called when the information button is clicked.
        /// It shows the information associated to the item
        /// </summary>        
        private void InformationButton_Click(object sender, RoutedEventArgs e)
        {
            if (Video.Visibility == Visibility.Visible)
            {
                Video.LoadedBehavior = MediaState.Manual;
                Video.Stop();
                Video.Visibility = Visibility.Hidden;
                PlayButton.Visibility = Visibility.Hidden;
                PauseButton.Visibility = Visibility.Hidden;
                Descripcion.Visibility = Visibility.Visible;
                Direccion.Visibility = Visibility.Visible;
                Mail.Visibility = Visibility.Visible;
                PaginaWeb.Visibility = Visibility.Visible;
                Telefono.Visibility = Visibility.Visible;
                Foto.Visibility = Visibility.Visible;
            }
            else
            {   
                PlayButton.Visibility = Visibility.Visible;
                PauseButton.Visibility = Visibility.Visible;
                Video.Visibility = Visibility.Visible;
                Descripcion.Visibility = Visibility.Hidden;
                Direccion.Visibility = Visibility.Hidden;
                Mail.Visibility = Visibility.Hidden;
                PaginaWeb.Visibility = Visibility.Hidden;
                Telefono.Visibility = Visibility.Hidden;
                Foto.Visibility = Visibility.Hidden;
            }
        }

        public event RoutedEventHandler click; 

        public void ShowOnMap_Click(object sender, RoutedEventArgs e)
        {
            if (click != null)
                click(this, e);
        }

        public event RoutedEventHandler closeClick;

        public void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            if (closeClick != null)
                closeClick(this, e);
        }

        private void OnPauseButtonPressed(object sender, RoutedEventArgs e)
        {
            Video.LoadedBehavior = MediaState.Manual;
            Video.Pause();
        }

        private void OnPlayButtonPressed(object sender, RoutedEventArgs e)
        {
            Video.LoadedBehavior = MediaState.Manual;
            Video.Play();
        }

        public event RoutedEventHandler printClick;

        private void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            if (printClick != null)
                printClick(this, e);
        }

        public event RoutedEventHandler mailClick;

        private void MailMapButton_Click(object sender, RoutedEventArgs e)
        {
            if (mailClick != null)
                mailClick(this, e);
        }
    }
}
